/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSky.factory;

import ru.jSky.generator.command.ModificationCommand;
import ru.jSky.interfaces.Enchantment;
import ru.jSky.interfaces.Major;
import ru.jSky.interfaces.NamedMajor;
import ru.jSky.interfaces.additional.Enchantmentable;
import ru.jSky.interfaces.additional.Templateable;

/**
 *
 * @author Rakev
 */
public class SimpleMajorModificationCommandFactory {

    public <T extends Major> ModificationCommand<T> createEnchantmeningtModificationCommand(final Enchantment enchantment) {
        return new ModificationCommand<T>() {
            @Override
            public T apply(T modificatingObject) {
                if (modificatingObject instanceof Enchantmentable) {
                    ((Enchantmentable) modificatingObject).setEnchantment(enchantment);
                }
                return modificatingObject;
            }
        };
    }

    public <T extends Major> ModificationCommand<T> createTemplatingModificationCommand(final T template) {
        return new ModificationCommand<T>() {
            @Override
            public T apply(T modificatingObject) {
                if (modificatingObject instanceof Templateable) {
                    ((Templateable) modificatingObject).setTemplate(template);
                }
                return modificatingObject;
            }
        };
    }

    public <T extends Major> ModificationCommand<T> createNamingModificationCommand(final String newName) {
        return new ModificationCommand<T>() {
            @Override
            public T apply(T modificatingObject) {
                if (modificatingObject instanceof NamedMajor) {
                    NamedMajor namingModificatingObject = (NamedMajor) modificatingObject;
                    namingModificatingObject.setName(newName);
                }
                return modificatingObject;
            }
        };
    }

    public <T extends Major> ModificationCommand<T> createConcatNamingModificationCommand(final String nameAppendix) {
        return new ModificationCommand<T>() {
            @Override
            public T apply(T modificatingObject) {
                if (modificatingObject instanceof NamedMajor) {
                    NamedMajor namingModificatingObject = (NamedMajor) modificatingObject;
                    String newName = namingModificatingObject.getName() + nameAppendix;
                    namingModificatingObject.setName(newName);
                }
                return modificatingObject;
            }
        };
    }
}
